package com.graph;

import java.util.Objects;
import java.util.TreeSet;
import java.util.concurrent.ConcurrentHashMap;

/**
 *code_repository_delta
 *@author huliangjun
 *@date 2018/11/30 11:23
 */
public class Edge {

    public static ConcurrentHashMap<String,Edge> edgeMap = new ConcurrentHashMap<String,Edge>();

    /** 开始平台*/
    String startVertex;
    /** 结束平台*/
    String endVertex;

    /** 两个平台间的跳跃点-按跳跃点的x坐标排序*/
    TreeSet<JumpPoint> jumpPoint;

    public Edge(String startVertex,String endVertex) {
        this.startVertex = startVertex;
        this.endVertex = endVertex;
        //按跳跃点的x坐标排序
        jumpPoint = new TreeSet<>((o1, o2) -> (int) (o1.getPixelPosX() - o2.getPixelPosX()));
    }

    public Edge addJumpPoint(JumpPoint jumpPoint){
        this.jumpPoint.add(jumpPoint);
        return this;
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) {
            return true;
        }
        if (o == null || getClass() != o.getClass()) {
            return false;
        }
        Edge edge = (Edge) o;
        return Objects.equals(startVertex, edge.startVertex) &&
            Objects.equals(endVertex, edge.endVertex);
    }

    @Override
    public int hashCode() {
        return Objects.hash(startVertex, endVertex);
    }

    public static ConcurrentHashMap<String, Edge> getEdgeMap() {
        return edgeMap;
    }

    public static void setEdgeMap(ConcurrentHashMap<String, Edge> edgeMap) {
        Edge.edgeMap = edgeMap;
    }

    public String getStartVertex() {
        return startVertex;
    }

    public void setStartVertex(String startVertex) {
        this.startVertex = startVertex;
    }

    public String getEndVertex() {
        return endVertex;
    }

    public void setEndVertex(String endVertex) {
        this.endVertex = endVertex;
    }

    public TreeSet<JumpPoint> getJumpPoint() {
        return jumpPoint;
    }

    public void setJumpPoint(TreeSet<JumpPoint> jumpPoint) {
        this.jumpPoint = jumpPoint;
    }
}
